home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 5 / Skunkware 5.iso / src / Tools / vg-2.03 / fatal.c next >
Encoding:
C/C++ Source or Header  |  1995-05-03  |  1.2 KB  |  52 lines

  1. /*
  2.  * Copyright (C) 1990-1992 Michael Davidson.
  3.  * All rights reserved.
  4.  *
  5.  * Permission to use, copy, modify, and distribute this software
  6.  * and its documentation for any purpose and without fee is hereby
  7.  * granted, provided that the above copyright notice appear in all
  8.  * copies and that both that copyright notice and this permission
  9.  * notice appear in supporting documentation.
  10.  *
  11.  * This software is provided "as is" without express or implied warranty.
  12.  */
  13.  
  14. #include    <stdio.h>
  15. #include    <stdlib.h>
  16. #include    <errno.h>
  17. #include    <string.h>
  18. #include    <stdarg.h>
  19.  
  20. #include    "vg.h"
  21.  
  22. extern char    *cmdname;
  23.  
  24. /*
  25.  * fatal(err, format, ...)    - print an error message and exit
  26.  */
  27. void
  28. fatal(
  29.     int        err,        /* system call error # or 0        */
  30.     char    *fmt,        /* message format string        */
  31.     ...                /* optional arguments            */
  32.     )
  33. {
  34.     va_list    args;
  35.  
  36.     cleanup();
  37.  
  38.     va_start(args, fmt);
  39.     if (err < 0)
  40.     (void) fprintf(stderr, "%s: internal error: ", cmdname);
  41.     else
  42.     (void) fprintf(stderr, "%s: fatal error: ", cmdname);
  43.     (void) vfprintf(stderr, fmt, args);
  44.     if (err > 0)
  45.     (void) fprintf(stderr, ": %s\n", strerror(err));
  46.     else
  47.     (void) fprintf(stderr, "\n");
  48.     va_end(args);
  49.  
  50.     exit(1);
  51. }
  52.